﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.Windows;

namespace QLThuoc_report
{
    public partial class Frm_TkeDoanhThuTheoThang : Form
    {
        public Frm_TkeDoanhThuTheoThang()
        {
            InitializeComponent();
        }
        private static int _Thang;

        public int Thang
        {
            get { return _Thang; }
            set { _Thang = value; }
        }
        private static int _Nam;

        public int Nam
        {
            get { return _Nam; }
            set { _Nam = value; }
        }
        private void Frm_TkeDoanhThuTheoThang_Load(object sender, EventArgs e)
        {
           SqlConnection conn = new SqlConnection("Data Source =(local);Initial Catalog=QLThuoc;Integrated Security=true");
           SqlDataAdapter da = new SqlDataAdapter("SELECT     dbo.tbl_Thuoc.TenThuoc AS 'Tên Thuốc', SUM(dbo.tbl_CTHoaDonBH.SoLuong) AS 'Số Lượng Đã Bán',   SUM(dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien / 100 + dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien) AS 'Tổng Tiền' FROM         dbo.tbl_CTHoaDonBH INNER JOIN  dbo.tbl_Thuoc ON dbo.tbl_CTHoaDonBH.MaThuoc = dbo.tbl_Thuoc.MaThuoc where Month( tbl_CTHoaDonBH.NgayBan) ='"+Thang+"' and year(tbl_CTHoaDonBH.NgayBan)='"+Nam+"' GROUP BY dbo.tbl_Thuoc.TenThuoc", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            //lay duong dan du chuy?n sang máy tính nào c?ng ko b? l?i, ko có c?ng ðc nhýng sang máy tính khác s? ko ch?y ðc
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin")) + "TKeDoanhThuTheoThang.rpt";
            TKeDoanhThuTheoThang report = new TKeDoanhThuTheoThang();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
        }
    }
}
